package com.ct.gd.passport.domain;

import java.util.Hashtable;
import java.util.StringTokenizer;

import com.up91.common.android.helper.L;

import android.util.Log;

/**
 * 通信证信息
 * 
 * @author Administrator
 * 
 */
public class PassportInfo {

	/** 通行证号 */
	private String id;
	/** 出生日期 */
	private String birthDate;
	/** 期限 */
	private String passLimitDate;
	/** 姓 */
	private String firstName;
	/** 名 */
	private String secondName;
	/** 收件地址 */
	private String emsaddr;
	/** 收件人 */
	private String addressee;
	/** 联系电话 */
	private String phoneNumber;
	/** 邮编 */
	private String postCode;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getBirthDate() {
		return birthDate;
	}

	public void setBirthDate(String birthDate) {
		this.birthDate = birthDate;
	}

	public String getPassLimitDate() {
		return passLimitDate;
	}

	public void setPassLimitDate(String passLimitDate) {
		this.passLimitDate = passLimitDate;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}

	public String getEmsaddr() {
		return emsaddr;
	}

	public void setEmsaddr(String emsaddr) {
		this.emsaddr = emsaddr;
	}

	public String getAddressee() {
		return addressee;
	}

	public void setAddressee(String addressee) {
		this.addressee = addressee;
	}

	public String getPhoneNumber() {
		return phoneNumber;
	}

	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}

	public String getPostCode() {
		return postCode;
	}

	public void setPostCode(String postCode) {
		this.postCode = postCode;
	}

	public void setArgs(Hashtable<String, String> args) {
		setBirthDate(args.get("CSRQ"));
		setEmsaddr(getUCString(args.get("emsaddr")));
		setAddressee(getUCString(args.get("emssjr")));
		setFirstName(getUCString(args.get("'XM_X'")));
		setSecondName(getUCString(args.get("'XM_M'")));
		setPassLimitDate(args.get("ZJYXQZ"));
		setPostCode(args.get("emsyb"));
		setPhoneNumber(args.get("DWDH"));
	}

	public String getUCString(String src) {
		try {
			StringTokenizer tokens = new StringTokenizer(src, "\\u");
			byte[] data = new byte[(tokens.countTokens() << 1) + 2];
			data[0] = (byte) 0xfe;
			data[1] = (byte) 0xff;
			int idx = 2;
			while (tokens.hasMoreElements()) {
				String content = tokens.nextToken();
				System.out.println(content);
				data[idx++] = (byte)(Integer.parseInt(content.substring(0, 2), 16) & 0xff);
				data[idx++] = (byte)(Integer.parseInt(content.substring(2), 16) & 0xff);
			}
			String result = new String(data, "utf-16");
			L.i("dbug", "getUI:" + src + " -> " + result);
			return result;
		} catch (Exception e) {
			L.w("getUCString error", src);
		}
		return src;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("BirthDate").append('=').append(getBirthDate());
		sb.append('\n').append("FirstName").append('=').append(getFirstName());
		sb.append('\n').append("SecondName").append('=').append(getSecondName());
		sb.append('\n').append("PassLimitDate").append('=').append(getPassLimitDate());
		return sb.toString();
	}

}
